package Jets.ui
{
   import flash.display.DisplayObjectContainer;
   import flash.events.MouseEvent;
   
   
   public class JAlert extends JPanel
   {
	  protected static var alerts:Array = [];
	  
	  public var yes:JPushButton;
	  protected var no:JPushButton;
	  protected var content:JText;
	  public var func:Function;
	  private var title:JRichLabel;
	  
      public function JAlert(parent:DisplayObjectContainer=null, cx:Number=0, cy:Number=0) 
	  {
         super(parent,cx,cy);
      }
      
      public static function pop(parent:DisplayObjectContainer,title:String="温馨提示",content:String="...",click:Function=null):JAlert 
	  {
         var alert:JAlert = null;
         if(alerts.length > 0)
         {
			 alert = alerts.pop();
         }
         else
         {
			 alert = new JAlert(null,0,0);
         }
		 alert.setTitle(title);
		 alert.setfunc(content,click);
		 alert.show(parent);
         return alert;
      }
      
      
      
      public function setTitle(text:Object) : void 
	  {
         this.title.data = text;
         this.addChild(this.title);
         this.title.x = (this.width - this.title.width) / 2;
      }
      
      override protected function init() : void 
	  {
         super.init();
         this.setSize(306,190);
         this.yes = new JPushButton(this,95,144,"",this.onyes);
         this.yes.setSize(100,23);
         this.yes.data = "我知道了";
         this.yes.textColor = 0x0c212b;
         this.content = new JText(this,27,54);
         this.content.setSize(250,75);
         this.content.text = "";
         this.content.textColor = 0x0c212b;
         this.title = new JRichLabel();
        // LayoutManager.reg(this,DockType.center);
      }
      
      public function setfunc(content:String, click:Function) : void 
	  {
         this.content.text = content;
         this.func = click;
      }
      
      private function onyes(event:MouseEvent) : void 
	  {
         this.hide();
         if(this.func != null)
         {
            this.func();
         }
         alerts.push(this);
      }
   }
}
